package com.lbtc.common;

import com.google.common.collect.Sets;
import com.lbtc.exception.LbtcMallException;
import com.lbtc.exception.LbtcMallExceptionEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import sun.awt.HKSCS;

import java.util.Set;

@Component
public class Constant {
    public static final String SALT = "Jiami@md5.com";
    public static final String LBTC_MALL_USER = "lbtc_mall_user";
    public static final String LBTC_MALL_ADMIN = "lbtc_mall_admin";

    public static String FILE_UPLOAD_DIR;
    @Value("${files.upload.dir}")
    private void setFileUploadDir(String fileUploadDir){
        this.FILE_UPLOAD_DIR = fileUploadDir;
    }

    /**
     * 枚举类，来说明订单状态
     */
    public enum OrderStatusEnum {
        CANCELED(0, "用户已取消"),
        NOT_PAY(10, "未付款"),
        PAID(20,"已付款"),
        DELIVERED(30,"已发货"),
        FINISHED(40,"交易完成");

        private int code;
        private String value;

        OrderStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public static OrderStatusEnum codeOf(int code) throws LbtcMallException {
            for (OrderStatusEnum orderStatusEnum:values() ) {
                if (orderStatusEnum.getCode() == code) {
                    return orderStatusEnum;
                }
            }
            throw new LbtcMallException(LbtcMallExceptionEnum.NO_ENUM);

        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }


    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price desc","price asc");
    }
    //定义商品上下架状态枚举接口
    public interface SaleStatus{
        int NOT_SALE=0;//商品下架状态
        int SALE=1;//商品上架状态
    }
    //定义商品被选中状态枚举接口
    public interface Cart{
        int UNCHECKED=0;//商品未选中状态
        int CHECKED=1;//商品被选中状态
    }

    public interface CartIsSelected {
        int UN_CHECKED = 0;//未选中状态
        int CHECKED = 1;//选中状态
    }
}
